﻿namespace DAL
{
    using System;
    using System.Collections.Generic;
    using System.Data.Objects;
    using System.Linq;
    using System.Linq.Expressions;

    public class GenericRepository<C, T> : IGenericRepository<C,T>
        where T : class
        where C : ObjectContext, new()
    {
        protected readonly C context;
        readonly ObjectSet<T> set;

        public GenericRepository()
        {
            context = new C();
            set = context.CreateObjectSet<T>();
        }

        public virtual IEnumerable<T> Find(Expression<Func<T, bool>> where)
        {
            return set.Where(where);
        }

        public C Context
        {
            get { return context; }
        }
    }
}
